import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/Table';
import { airportList } from '@apps/ant-bus/src/views/business/airport/data/api';
import { getTargetListByAirport } from '@apps/ant-bus/src/views/business/goods/excludeGoods/data/api';

export const columns: BasicColumn[] = [
  {
    title: '目标名称',
    dataIndex: 'targetName',
    width: 150,
  },
  {
    title: '非共用物品',
    dataIndex: 'goodsName',
    width: 150,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'goodsName',
    label: '非共用',
    labelWidth: 500,
    component: 'Input',
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '目标Id',
    field: 'targetId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '目标所属机场',
    field: 'airportId',
    component: 'ApiSelect',
    required: true,
    dynamicDisabled: true,
    componentProps: ({ formModel }) => {
      return {
        api: airportList,
        labelField: 'airportName',
        valueField: 'airportId',
        immediate: true,
        showSearch: true,
        onChange: airportId => {
          formModel.goodsId = null;
        },
      };
    },
  },
  {
    label: '非共用物品',
    field: 'goodsId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      let airportId = formModel.airportId;
      let neGoodsId = formModel.targetId;
      return {
        api: getTargetListByAirport,
        params: { airportId: airportId, neGoodsId: neGoodsId },
        labelField: 'targetName',
        valueField: 'targetId',
        immediate: true,
        showSearch: true,
      };
    },
  },
];
